package com.example.demo.controller;

import com.example.demo.entity.User;
import com.example.demo.service.UserService;
import com.example.demo.utils.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/user")
public class TestController {
    @Autowired
    private UserService userService;

@PostMapping("/login")
    public User login(String username, String pwd) {
        return userService.login(username,pwd);
    }

    @PostMapping("/add")
    public String add(String username, String pwd, Integer age) {
        if (StringUtils.ttt(username))return "用户名不能为空";
        if (StringUtils.ttt(pwd))return "密码不能为空";
        if (age!=null&&age<=0)return "年龄输入错误";
        Boolean res = userService.add(username,pwd,age);
        if (res==true)return "添加成功";
        return "添加失败";
    }
}
